<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<input type="file" id="fileInput" onchange="handleFileInputChange(event)" />
<script>
    function chunkFile(file, chunkSize) {
        //? 存储分片
        const fileChunkList = [];
        let cur = 0;
        while (cur < file.size) {
            //? File对象的slice方法返回的是一个新的Blob对象
            fileChunkList.push({ fileChunk: file.slice(cur, cur + chunkSize) });
            cur += chunkSize;
        }
        return fileChunkList;
    }
    function handleFileInputChange(event) {
        //? 拿到文件
        const file = event.target.files[0];
        const chunkSize = 1024 * 1024;
        //? 开始分片
        console.log(chunkFile(file, chunkSize));
    }
</script>
</body>
</html>
